有了登入 我們就來寫個會員管理頁面吧!
把views/user.php做一下改變
<?php
$link = 'http://localhost/test/';
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>公佈欄</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="<?=$link;?>css/bootstrap-responsive.min.css" rel="stylesheet">
<link href="<?=$link;?>css/bootstrap.min.css" rel="stylesheet" media="screen">
<script src="<?=$link;?>js/jquery.js"></script>
<script src="<?=$link;?>js/bootstrap.min.js"></script>
<style>
#heig{
height:10px;
}
#color{
background-color: #666;
color: #FFF;
}
#color2{
background-color: #999;
}
</style>
<div class="container">
<table width="1200" border="1" class="table table-bordered table-condensed table-striped table-hover">
<tr>
<td colspan="5" id="color"><div align="center"><strong><h2>會員管理</h2></strong></div></td>
</tr>
<tr>
<td width="150"><div align="center"><strong>快速新增會員</strong></div></td>
<td colspan="4"><form id="form1" name="form1" method="post" action="<?=$link;?>index1.php/users/AddUser" class="form-inline">
<div id="heig">
帳號:
<label>
<input type="text" name="account" id="account" />
</label>
密碼:
<label>
<input type="password" name="password" id="password" />
</label>
<label>
<input type="submit" value="新增" class="btn" />
</label>
</div>
</form></td>
</tr>
<tr>
<td id="color2"><div align="center"><strong>項次</strong></div></td>
<td id="color2"><div align="center"><strong>帳號</strong></div></td>
<td id="color2"><div align="center"><strong>備註</strong></div></td>
<td id="color2"><div align="center"><strong>權限</strong></div></td>
<td id="color2"><div align="center"><strong>管理</strong></div></td>
</tr>
<?php foreach($query->result_array() as $key=>$row):?>
<tr>
<td><div align="center"><?=$key+1;?></div></td>
<td><div align="center"><?=$row['account'];?></div></td>
<td><div align="center"><?=$row['remark'];?></div></td>
<td><div align="center">
<?php
if($row['class']=="0"){
echo "最高權限";
}else{
echo "一般會員";
}
?>
</div></td>
<td><div align="center">
<div class="btn-group">
<button class="btn">修改</button>
<button class="btn">刪除</button>
</div>
</div></td>
</tr>
<?php endforeach; ?>
</table>
</div>
然後 controllers/users.php 也改一下
<?php
class users extends CI_Controller{
function __construct() {
parent::__construct();
//載入資料庫行為
$this->load->model('users_sql');
/**請參考 http://www.codeigniter.org.tw/user_guide/helpers/url_helper.html **/
$this->load->helper('url');
}
function index(){
$this->load->view('login');
}
function login(){
$where = $this->input->post();
$query = $this->users_sql->where_array($where,'users');
/*num_rows() 請參考 : http://www.codeigniter.org.tw/user_guide/database/results.html*/
if($query->num_rows() > 0){
$this->user();
}else{
redirect(site_url().'users/index');
}
}
function user(){
$data['query'] = $this->users_sql->all('users');
$this->load->view('user',$data);
}
}
?>
在來models/users_sql.php
新增一個方法
function all($table){
$query = $this->db->get($table);
return $query;
}
這樣因該可以看到頁面
完成圖